package com.moive.news.tqnewsapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.moive.news.tqnewsapplication.R;
import com.moive.news.tqnewsapplication.base.Adapter.BaseListAdapter;
import com.moive.news.tqnewsapplication.entity.HistoricalBean;
import com.moive.news.tqnewsapplication.utils.DateUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/12/25.
 */

public class HistoricalAdapter extends BaseListAdapter<HistoricalBean.DataBean> {
    Context context;

    public HistoricalAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected View getItemView(int position, View convertView, ViewGroup parent, List<HistoricalBean.DataBean> item) {
        ViewHoder viewHoder=null;
        if (viewHoder==null){
            viewHoder=new ViewHoder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_newsinfo, null);
            viewHoder.news_img = convertView.findViewById(R.id.news_img);
            viewHoder.news_src = convertView.findViewById(R.id.news_src);
            viewHoder.news_time = convertView.findViewById(R.id.news_time);
            viewHoder.news_title = convertView.findViewById(R.id.news_title);
            convertView.setTag(viewHoder);
        }else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        Glide.with(context)
                .load(item.get(position).getNewsTitleImg())
                .centerCrop()
                .dontAnimate()
                .placeholder(R.drawable.icon)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(viewHoder.news_img);
        viewHoder.news_src.setText(item.get(position).getNewsSrc());
        viewHoder.news_title.setText(item.get(position).getNewsTitle());
        String newtime = DateUtil.getDescriptionTimeFromTimestamp(item.get(position).getCreateDate());
        viewHoder.news_time.setText(newtime);
        return convertView;
    }
    class ViewHoder {
        ImageView news_img;
        TextView news_title, news_src, news_time;
    }
}
